package labox.innovation.gameserver.templates.item;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javolution.util.FastList;
import labox.innovation.config.Config;
import labox.innovation.gameserver.model.L2Effect;
import labox.innovation.gameserver.model.L2ItemInstance;
import labox.innovation.gameserver.model.L2Object;
import labox.innovation.gameserver.model.L2Skill;
import labox.innovation.gameserver.model.actor.L2Character;
import labox.innovation.gameserver.model.actor.instance.L2SummonInstance;
import labox.innovation.gameserver.model.itemcontainer.Inventory;
import labox.innovation.gameserver.model.itemcontainer.PcInventory;
import labox.innovation.gameserver.network.serverpackets.SystemMessage;
import labox.innovation.gameserver.network.SystemMessageId;
import labox.innovation.gameserver.skills.Env;
import labox.innovation.gameserver.skills.Stats;
import labox.innovation.gameserver.skills.conditions.Condition;
import labox.innovation.gameserver.skills.funcs.AttributeStringSplice;
import labox.innovation.gameserver.skills.funcs.Func;
import labox.innovation.gameserver.skills.funcs.FuncTemplate;
import labox.innovation.gameserver.skills.funcs.Lambda;
import labox.innovation.gameserver.templates.StatsSet;
import labox.innovation.gameserver.templates.effects.EffectTemplate;

/**
 * This class contains all informations concerning the item (weapon, armor,
 * etc).<BR>
 * Mother class of :
 * <LI>L2Armor</LI>
 * <LI>L2EtcItem</LI>
 * <LI>L2Weapon</LI>
 * 
 * @version $Revision: 1.7.2.2.2.5 $ $Date: 2005/04/06 18:25:18 $
 */
public abstract class L2Item {
	// ����1
	public static final int TYPE1_WEAPON_RING_EARRING_NECKLACE = 0;  //��������ָ�������� ��

	public static final int TYPE1_SHIELD_ARMOR = 1;    // װ����

	public static final int TYPE1_ITEM_QUESTITEM_ADENA = 4; //������
	
	//����2

	public static final int TYPE2_WEAPON = 0;

	public static final int TYPE2_SHIELD_ARMOR = 1;

	public static final int TYPE2_ACCESSORY = 2;

	public static final int TYPE2_QUEST = 3;  //������Ʒ

	public static final int TYPE2_MONEY = 4;

	public static final int TYPE2_OTHER = 5;

	public static final int TYPE2_PET_WOLF = 6;

	public static final int TYPE2_PET_HATCHLING = 7;

	public static final int TYPE2_PET_STRIDER = 8;

	public static final int TYPE2_PET_BABY = 9;

	public static final int TYPE2_PET_EVOLVEDWOLF = 10;
	
	public static final int TYPE2_POTION = 11;

	
	public static final int SLOT_NONE = 0x0000;

	public static final int SLOT_NECK = 0x0001;

	public static final int SLOT_R_FINGER = 0x0002;

	public static final int SLOT_L_FINGER = 0x0004;

	public static final int SLOT_LR_FINGER = 0x0006; //����װ���� �����ֽ�ָ��λ

	public static final int SLOT_HEAD = 0x0008;
	
	public static final int SLOT_HAND   = 0x0010;

	public static final int SLOT_CHEST = 0x0020;

	public static final int SLOT_LEGS = 0x0030;

	public static final int SLOT_FEET = 0x0040;

	public static final int SLOT_SHOULDER = 0x0050;

	public static final int SLOT_R_BRACELET = 0x0060;

	public static final int SLOT_L_BRACELET = 0x0101;
	
	public static final int SLOT_LR_BRACELET = 0x0161;

	public static final int SLOT_DECO = 0x0080;   ////����

	public static final int SLOT_BELT = 0x0090;  //����

	public static final int SLOT_STRIDER = 0x0100;
	
	public static final int SLOT_WING    = 0x0200;
	
	/**
	 * ��Ʒ����������
	 * ͨ��������� ���Ի�����е���Ʒ����
	 */
	private FuzeItemCondition _itemCondition;

	private final int _itemId;

	private final String _name;

	private final int _type1; // needed for item list (inventory)

	private final int _type2; // different lists for armor, weapon, etc

	private final boolean _stackable;
	//��������
	private final int _stackmaxnums;

	//����ʱ��
	private final int _time;
	
	//����۸�
	private final int _buyprice;
	//�����۸�
	private final int _sellprice;

	//���� �Ƿ��ʱ
	private final boolean _isofftime;
	//�ܷ��
	private final boolean _canbinding;
	
	//�ܷ�ʹ��
	private final boolean _canuse;
	
	private final boolean _stayafterdie;
	
	//��Ʒͼ��id
	private final int     _iconid;
	//չʾͼ��
	private final int     _displayid;
	
	// ��Ʒ�ȼ�
	private final int     _itemlvl;
	
	//�Ƿ�������Ʒ
//	private final boolean _isquest;
	
	//�b�䲿λ
	private final int _bodyPart;

	private final int _referencePrice;

	private final boolean _sellable;

	private final boolean _dropable;

	private final boolean _destroyable;

	private final boolean _tradeable;

	private final boolean _depositable;

	private final boolean _common;

	private final boolean _heroItem;

	private final boolean _pvpItem;
	
	private final String _strDes; //��Ʒ����

	@SuppressWarnings("unchecked")
	protected final Enum _type;

	protected FuncTemplate[] _funcTemplates;

	protected EffectTemplate[] _effectTemplates;

	protected L2Skill[] _skills;

	protected List<Condition> _preConditions = new FastList<Condition>();

	private static final Func[] _emptyFunctionSet = new Func[0];

	protected static final L2Effect[] _emptyEffectSet = new L2Effect[0];
	
	//add
	//���ӵ����� ����
	//������������ ��ֵ
	protected String _randProperty;
	//���� ��������
	protected String _randtypeattri;
	//�����Ǽ�
	protected int _starlvl;
	//����Ʒ��
	protected int _gradelvl;
	//�������
	protected int _inscribe;
	//���Ƽ�
	protected int _identify;
	//ʹ�ú��Ƿ����
	protected boolean _useReduce; 
	
	//���� ��Ʒģ�������ֵ
	public Map<Integer,Integer > _attributs = new HashMap<Integer,Integer>();
	
	//��Ʒ��������
	public StringBuilder _itemAttributeDescription = new StringBuilder();
	
	protected String  _itemAttributeDes = null;
	
	//��Ʒ��ȴ����
	//TODO �� ��Ҫ���߲߻� �������ֶ�
	/**
	 * ��Ʒ����ȴ����  ������ Ӧ�ø� ���ܵ���ȥ���� ��һ��ϵ�µ�
	 * ���û��ָ�� Ϊ -1�� ��ô����Ʒ �����κ�������Ʒʹ�õ�Ӱ��
	 */
	protected int _catCool;   
	/**
	 * ��Ʒ�Ĺ�����ȴ����  ������ Ӧ�ø� ���ܵĹ�����ȥ���� ��һ��ϵ�µ�
	 * ���û��ָ�� Ϊ -1�� ��ô����Ʒ �����κ�������Ʒ����CDӰ��
	 */
	protected int _catGlobalCool;
	
	//add

	/**
	 * Constructor of the L2Item that fill class variables.<BR>
	 * <BR>
	 * <U><I>Variables filled :</I></U><BR>
	 * <LI>type</LI>
	 * <LI>_itemId</LI>
	 * <LI>_name</LI>
	 * <LI>_type1 & _type2</LI>
	 * <LI>_weight</LI>
	 * <LI>_crystallizable</LI>
	 * <LI>_stackable</LI>
	 * <LI>_materialType & _crystalType & _crystlaCount</LI>
	 * <LI>_duration</LI>
	 * <LI>_bodypart</LI>
	 * <LI>_referencePrice</LI>
	 * <LI>_sellable</LI>
	 * 
	 * @param type :
	 *            Enum designating the type of the item
	 * @param set :
	 *            StatsSet corresponding to a set of couples (key,value) for
	 *            description of the item
	 */
	protected L2Item(Enum<?> type, StatsSet set) {		
		_type = type;
		_itemId = set.getInteger("item_id");
		_name = set.getString("name");
		_type1 = set.getInteger("type1"); // needed for item list (inventory)
		_type2 = set.getInteger("type2"); // different lists for armor,
											// weapon, etc

		_itemlvl = set.getInteger("itemlevel"); 
		_iconid = set.getInteger("iconid");
		_displayid = set.getInteger("displayid", -1 );
		
		_strDes = set.getString("description", "");
		
		_stackable = set.getBool("stackable", false);
		_stackmaxnums = set.getInteger("stackmaxnums", 1);
		
		_catCool = set.getInteger("catcool", -1);
		_catGlobalCool = set.getInteger("catglobalcool", -1 );

//		_isquest   = set.getBool("isquest", false);
		
		_time = set.getInteger("time", -1);
		_isofftime = set.getBool("isofftime", false);
		_bodyPart = set.getInteger("bodypart");
		_referencePrice = set.getInteger("price", 0 );

		_stayafterdie = set.getBool("stayafterdie", true);
		_canbinding = set.getBool("canbinding", false);
		_canuse     = set.getBool("canuse", false);
		_sellable = set.getBool("sellable", true);
		_dropable = set.getBool("dropable", true);
		_destroyable = set.getBool("destroyable", true);
		_tradeable = set.getBool("tradeable", true);
		_depositable = set.getBool("depositable", true);
		
		_useReduce = set.getBool("usereduce", true);
		
		_buyprice = set.getInteger("buyprice", 0);
		_sellprice = set.getInteger("sellprice", 0);

		//�����ֶ�
		_randtypeattri = set.getString("attritype", null);
		_randProperty  = set.getString("randattrivalue", null);
		_starlvl       = set.getInteger("itemstar", 0);
		_gradelvl      = set.getInteger("itemgrade", -1);
		_inscribe      = set.getInteger("iteminscribe", -1);
		_identify      = set.getInteger("itemidentify", -1);
		
		_common = (_itemId >= 12006 && _itemId <= 12361)
				|| (_itemId >= 11605 && _itemId <= 12308);
		_heroItem = (_itemId >= 6611 && _itemId <= 6621)
				|| (_itemId >= 9388 && _itemId <= 9390) || _itemId == 6842;

		_pvpItem = (_itemId >= 10667 && _itemId <= 10792)
				|| (_itemId >= 10793 && _itemId <= 10835)
				|| (_itemId >= 12852 && _itemId <= 12977)
				|| (_itemId >= 14363 && _itemId <= 14519)
				|| (_itemId >= 14520 && _itemId <= 14525) || _itemId == 14528
				|| _itemId == 14529 || _itemId == 14558;
		

	}
	
	/**
	 *  �����Ʒ����
	 * @return
	 */
	public String getItemDes()
	{
		return _strDes;
	}
	
	/**
	 * �Ƿ��ǵ���
	 * @return
	 */
	public boolean isEtcItem(){
		return _type1==TYPE1_ITEM_QUESTITEM_ADENA;
	}
	
	/**
	 *  �����Ʒ ������
	 *  ���治Ӧ�õ����������
	 * @return
	 */
	public FuzeItemCondition setItemCondition()
	{
		if( _itemCondition == null ){
			_itemCondition = new FuzeItemCondition();
		}
		
		return _itemCondition;
	}
	
	/**
	 *  ���  ��Ʒ����������
	 *  ͨ������� ���Ի�� ��Ʒ��������������
	 * @return
	 */
	public FuzeItemCondition getItemCondition()
	{
		return _itemCondition;
	}
	
	

	/**
	 * Returns the itemType.
	 * 
	 * @return Enum
	 */
	@SuppressWarnings("unchecked")
	public Enum getItemType() {
		return _type;
	}

	/**
	 * Returns the time of the item
	 * 
	 * @return int
	 * ���� -1��ʾ �����Ʒ û��ʱ������.
	 */
	public final int getTime() {
		return _time;
	}
	
	/**
	 *  �����Ʒ����ȴ����
	 *  -1��ʾ ������Ʒ��ȴ����Ӱ��
	 * @return
	 */
	public final int getCatCool()
	{
		return _catCool;
	}
	
	/**
	 *  �����Ʒ ����CD����ȥ����
	 *  -1��ʾ  û�й���CDӰ��
	 * @return
	 */
	public final int getGlobalCatCool()
	{
		return _catGlobalCool;
	}

	/**
	 * Returns the ID of the iden
	 * 
	 * @return int
	 */
	public final int getItemId() {
		return _itemId;
	}
	
	/**
	 *  ��� ��Ʒ�ȼ�
	 * @return
	 */
	public final int getItemLvl()
	{
		return _itemlvl;
	}

	public abstract int getItemMask();
	//�;�ֵ����
	public abstract int getEnduranceup();

	/**
	 *��Ʒ�������ʹ���С��С��
	 * 
	 * @return int
	 */
	public final int getType2() {
		return _type2;
	}

	/**
	 * Returns the name of the item
	 * 
	 * @return String
	 */
	public final String getName() {
		return _name;
	}

	/**
	 * Return the part of the body used with the item.
	 * 
	 * @return int
	 */
	public final int getBodyPart() {
		return _bodyPart;
	}
	
	/**
	 *  �@���b��ڲ��λ��
	 * @return
	 */
	public final int getBodySlot()
	{
		switch( getBodyPart() )
		{
			case L2Item.SLOT_NECK:
				return Inventory.PAPERDOLL_NECK;
			case L2Item.SLOT_R_FINGER:
				return Inventory.PAPERDOLL_RFINGER;
			case L2Item.SLOT_L_FINGER:
				return Inventory.PAPERDOLL_LFINGER;
			case L2Item.SLOT_HEAD:
				return Inventory.PAPERDOLL_HEAD;
			case L2Item.SLOT_CHEST:
				return Inventory.PAPERDOLL_CHEST;
			case L2Item.SLOT_LEGS:
				return Inventory.PAPERDOLL_LEGS;
			case L2Item.SLOT_FEET:
				return Inventory.PAPERDOLL_FEET;
			case L2Item.SLOT_L_BRACELET:
				return Inventory.PAPERDOLL_LBRACELET;
			case L2Item.SLOT_R_BRACELET:
				return Inventory.PAPERDOLL_RBRACELET;
			case L2Item.SLOT_DECO:
				return Inventory.PAPERDOLL_DECO;
			case L2Item.SLOT_WING:
				return Inventory.PAPERDOLL_WING;
			case L2Item.SLOT_HAND:
				return Inventory.PAPERDOLL_HAND;
			case L2Item.SLOT_SHOULDER:
				return Inventory.PAPERDOLL_SHOULDER;
		}
		
		return -1;
	}

	/**
	 * ��Ʒ��������
	 * 
	 * @return int
	 */
	public final int getType1() {
		return _type1;
	}

	/**
	 * Returns if the item is stackable
	 * 
	 * @return boolean
	 */
	public final boolean isStackable() {
		return _stackable;
	}
	
	/**
	 * �Ƿ���Ǯ
	 * @return
	 */
	public boolean isMoney()
	{
		return ( getItemId() == PcInventory.MONEY_NOTE_ID ||  getItemId() ==  PcInventory.MONEY_SLIVER_ID
				|| getItemId() == PcInventory.MONEY_YAUNBAO_ID || getItemId() == PcInventory.MONEY_YAUNBAO_ID || getItemId() == PcInventory.MONEY_POINT_ID);
	}

	/**
	 * Returns if the item is consumable
	 * 
	 * @return boolean
	 */
	public boolean isConsumable() {
		return false;
	}

	public boolean isEquipable() {
		return this.getBodyPart() != 0
				&& !(this.getItemType() instanceof L2EtcItemType);
	}

	/**
	 * Returns the price of reference of the item
	 * 
	 * @return int �����Ʒ�Ĳο��۸� �����Ʒʱ����ĵ� �Ǽ۸��ǹ̶��ġ� ����ǿ���ĵ� ��Ҫ����
	 */
	public final int getReferencePrice() {
		//
		return (isConsumable() ? (int) (_referencePrice * Config.RATE_CONSUMABLE_COST)
				: _referencePrice);
	}

	/**
	 * Returns if the item can be sold
	 * 
	 * @return boolean
	 */
	public final boolean isSellable() {
		return _sellable;
	}

	/**
	 * Returns if the item can dropped
	 * 
	 * @return boolean
	 */
	public final boolean isDropable() {
		return _dropable;
	}

	/**
	 * Returns if the item can destroy
	 * 
	 * @return boolean
	 */
	public final boolean isDestroyable() {
		return _destroyable;
	}

	/**
	 * Returns if the item can add to trade
	 * 
	 * @return boolean
	 */
	public final boolean isTradeable() {
		return _tradeable;
	}

	/**
	 * Returns if the item can be put into warehouse
	 * 
	 * @return boolean
	 */
	public final boolean isDepositable() {
		return _depositable;
	}

	/**
	 * Returns if item is common �Ƿ� ��ͨ��Ʒ
	 * 
	 * @return boolean
	 */
	public final boolean isCommon() {
		return _common;
	}

	/**
	 * Returns if item is hero-only
	 * 
	 * @return
	 */
	public final boolean isHeroItem() {
		return _heroItem;
	}

	/**
	 * Returns if item is pvp
	 * 
	 * @return
	 */
	public final boolean isPvpItem() {
		return _pvpItem;
	}

	/**
	 * Returns if item is for hatchling
	 * 
	 * @return boolean
	 */
	public boolean isForHatchling() {
		return (_type2 == TYPE2_PET_HATCHLING);
	}

	/**
	 * Returns if item is for strider
	 * 
	 * @return boolean
	 */
	public boolean isForStrider() {
		return (_type2 == TYPE2_PET_STRIDER);
	}

	/**
	 * Returns if item is for wolf
	 * 
	 * @return boolean
	 */
	public boolean isForWolf() {
		return (_type2 == TYPE2_PET_WOLF);
	}

	/**
	 * Returns if item is for Great wolf
	 * 
	 * @return boolean
	 */
	public boolean isForEvolvedWolf() {
		return (_type2 == TYPE2_PET_EVOLVEDWOLF);
	}

	/**
	 * Returns if item is for wolf
	 * 
	 * @return boolean
	 */
	public boolean isForBabyPet() {
		return (_type2 == TYPE2_PET_BABY);
	}
	
	/**
	 * ��������ֵ
	 * @param index  ��������id
	 * @param value  ����ֵ
	 */
	public void putAttribute( int index, int value)
	{
		if( index== -1 )
			return;
		_attributs.put(index, value);
	}
	
	/**
	 *  ���ָ�� ����ֵ
	 * @param index  ��������id
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public int getAttribute( int index )
	{
		return _attributs.get(index);
	}
	
	/**
	 *  �����С���?����
	 * @return
	 */
	public int getPAtkMin()
	{
		return getAttribute( Stats.MIN_POWER_ATTACK.ordinal() );
	}
	
	/**
	 *  ���������?��
	 * @return
	 */
	public int getPAtkMax()
	{
		return getAttribute( Stats.MAX_POWER_ATTACK.ordinal() );
	}
	
	/**
	 *  ��� ��С��ħ������
	 * @return
	 */
	public int getMAtkMin()
	{
		return getAttribute( Stats.MIN_MAGIC_ATTACK.ordinal() );
	}
	
	public int getMAtkMax()
	{
		return getAttribute( Stats.MAX_MAGIC_ATTACK.ordinal() );
	}
	
	/**
	 *  ����������
	 * @return
	 */
	public int getPDef()
	{
		return getAttribute( Stats.POWER_DEFENCE.ordinal() );
	}
	
	/**
	 *  ���ħ������
	 * @return
	 */
	public int getMDef()
	{
		return getAttribute( Stats.MAGIC_DEFENCE.ordinal() );
	}
	
	/**
	 *  �������ֵ����
	 * @return
	 */
	public int getHpMax()
	{
		return getAttribute( Stats.MAX_HP.ordinal() );
	}


	/**
	 * Returns array of Func objects containing the list of functions used by
	 * the item
	 * 
	 * @param instance :
	 *            L2ItemInstance pointing out the item
	 * @param player :
	 *            L2Character pointing out the player
	 * @return Func[] : array of functions
	 */
	public Func[] getStatFuncs(L2ItemInstance instance, L2Character player) {
		if (_funcTemplates == null)
			return _emptyFunctionSet;
		List<Func> funcs = new FastList<Func>();
		for (FuncTemplate t : _funcTemplates) {
			Env env = new Env();
			env.player = player;
			env.target = player;
			env.item = instance;
			Func f = t.getFunc(env, this); // skill is owner
			if (f != null)
				funcs.add(f);
		}
		if (funcs.isEmpty())
			return _emptyFunctionSet;
		return funcs.toArray(new Func[funcs.size()]);
	}

	/**
	 * Returns the effects associated with the item.
	 * 
	 * @param instance :
	 *            L2ItemInstance pointing out the item
	 * @param player :
	 *            L2Character pointing out the player
	 * @return L2Effect[] : array of effects generated by the item
	 */
	public L2Effect[] getEffects(L2ItemInstance instance, L2Character player) {
		if (_effectTemplates == null)
			return _emptyEffectSet;
		List<L2Effect> effects = new FastList<L2Effect>();
		for (EffectTemplate et : _effectTemplates) {
			Env env = new Env();
			env.player = player;
			env.target = player;
			env.item = instance;
			L2Effect e = et.getEffect(env);
			if (e != null) {
				e.scheduleEffect();
				effects.add(e);
			}
		}
		if (effects.isEmpty())
			return _emptyEffectSet;
		return effects.toArray(new L2Effect[effects.size()]);
	}

	/**
	 * Returns effects of skills associated with the item.
	 * 
	 * @param caster :
	 *            L2Character pointing out the caster
	 * @param target :
	 *            L2Character pointing out the target
	 * @return L2Effect[] : array of effects generated by the skill
	 * 
	 * public L2Effect[] getSkillEffects(L2Character caster, L2Character target) {
	 * if (_skills == null) return _emptyEffectSet; List<L2Effect> effects =
	 * new FastList<L2Effect>();
	 * 
	 * for (L2Skill skill : _skills) { if (!skill.checkCondition(caster, target,
	 * true)) continue; // Skill condition not met
	 * 
	 * if (target.getFirstEffect(skill.getId()) != null)
	 * target.removeEffect(target.getFirstEffect(skill.getId())); for (L2Effect
	 * e : skill.getEffects(caster, target)) effects.add(e); } if
	 * (effects.isEmpty()) return _emptyEffectSet; return effects.toArray(new
	 * L2Effect[effects.size()]); }
	 */
	/**
	 * Add the FuncTemplate f to the list of functions used with the item
	 * 
	 * @param f :
	 *            FuncTemplate to add
	 */
	public void attach(FuncTemplate f) {
		// If _functTemplates is empty, create it and add the FuncTemplate f in
		// it
		if (_funcTemplates == null) {
			_funcTemplates = new FuncTemplate[] { f };
		} else {
			int len = _funcTemplates.length;
			FuncTemplate[] tmp = new FuncTemplate[len + 1];
			// Definition : arraycopy(array source, begins copy at this position
			// of source, array destination, begins copy at this position in
			// dest,
			// number of components to be copied)
			System.arraycopy(_funcTemplates, 0, tmp, 0, len);
			tmp[len] = f;
			_funcTemplates = tmp;
		}
	}

	/**
	 * Add the EffectTemplate effect to the list of effects generated by the
	 * item
	 * 
	 * @param effect :
	 *            EffectTemplate
	 */
	public void attach(EffectTemplate effect) {
		if (_effectTemplates == null) {
			_effectTemplates = new EffectTemplate[] { effect };
		} else {
			int len = _effectTemplates.length;
			EffectTemplate[] tmp = new EffectTemplate[len + 1];
			// Definition : arraycopy(array source, begins copy at this position
			// of source, array destination, begins copy at this position in
			// dest,
			// number of components to be copied)
			System.arraycopy(_effectTemplates, 0, tmp, 0, len);
			tmp[len] = effect;
			_effectTemplates = tmp;
		}
	}
	
	
	/**
	 * ��� ���������� �� ֵ
	 */
	
	public String getRandProperty()
	{
		return _randProperty;
	}
	
	/**
	 *  ��������������
	 * @return
	 */
	public String getRandTypeAttri()
	{
		return _randtypeattri;
	}
	
	/**
	 *  �����Ʒ���� ������
	 *  ���� -1 ��ô �Ƕ��Ƽ�
	 * @return
	 */
	public int getMusIdnetify()
	{
		return _identify;
	}
	
	/**
	 *  �����Ʒ�Ķ���  �������
	 *  ���� -1 ��ô �� ����  �������
	 * @return
	 */
	public int getMustInscribe()
	{
		return _inscribe;
	}
	
	/**
	 *  �����Ʒ���Ƶ�׷�ǵȼ�
	 * @return
	 */
	public int getMustStarLvl()
	{
		return _starlvl;
	}
	
	
	/**
	 * �����Ʒ��Ʒ��
	 * @return
	 */
	public int getItemGrade()
	{
		return _gradelvl;
	}
	
	/**
	 * �Ƿ���������� ��Ҫ���
	 * @return
	 */
	public boolean hasRandProperty()
	{
		return _randProperty != null;
	}
	
	
	public int getBuyPrice()
	{
		return _buyprice;
	}
	
	public int getSellPrice()
	{
		return _sellprice;
	}
	
	public boolean getOffTime()
	{
		return _isofftime;
	}
	
	public boolean getCanBinding()
	{
		return _canbinding;
	}
	
	/**
	 * �ܷ�ʹ��
	 * @return
	 */
	public boolean getCanuse()
	{
		return _canuse;
	}
	
	public boolean getCanIdentify()
	{
		return false;
	}
	
	public boolean getCanInscribe()
	{
		return false;
	}
	
	public boolean getCanComposite()
	{
		return false;
	}
	
	public boolean getCanStar()
	{
		return false;
	}
	
	public boolean getCanpunch()
	{
		return false;
	}
	
	public boolean getCanmosaic()
	{
		return false;
	}
	
	public boolean getCanmelt()
	{
		return false;
	}
	
	public boolean getIsset()
	{
		return false;
	}
	
	public boolean getCanrepair()
	{
		return true;
	}
	
	
	/**
	 * �Ƿ�� ʹ�ü���
	 * @return
	 */
	public boolean isUseReduce()
	{
		return _useReduce;
	}
	
	public boolean stayAfterDie()
	{
		return _stayafterdie;
	}
	
	/**
	 *  ��� ��Ʒͼ��id
	 * @return
	 */
	public int getItemIconId()
	{
		return _iconid;
	}
	
	/**
	 *  �����Ʒչʾ ͼ��
	 * @return
	 */
	public int getDisplayIconId()
	{
		return _displayid;
	}
	
	/**
	 * �Ƿ��� ������Ʒ
	 * @return
	 */
	public boolean isQuestItem()
	{
		return _type == L2EtcItemType.QUEST;
	}
	
	/**
	 * Add the L2Skill skill to the list of skills generated by the item
	 * 
	 * @param skill :
	 *            L2Skill
	 */
	public void attach(L2Skill skill) {
		if (_skills == null) {
			_skills = new L2Skill[] { skill };
		} else {
			int len = _skills.length;
			L2Skill[] tmp = new L2Skill[len + 1];
			// Definition : arraycopy(array source, begins copy at this position
			// of source, array destination, begins copy at this position in
			// dest,
			// number of components to be copied)
			System.arraycopy(_skills, 0, tmp, 0, len);
			tmp[len] = skill;
			_skills = tmp;
		}
	}
	
	/**
	 *  ��� ������������
	 * @return
	 */
	public final List<Condition> getAllCondions()
	{
		return _preConditions;
	}

	public final void attach(Condition c) {
		if (!_preConditions.contains(c))
			_preConditions.add(c);
	}

	public final L2Skill[] getItemSkills() {
		return _skills;
	}

	public boolean checkCondition(L2Character activeChar, L2Object target,boolean sendMessage) {
		if (activeChar.isGM() && !Config.GM_ITEM_RESTRICTION)
			return true;

		for (Condition preCondition : _preConditions) {
			if (preCondition == null)
				return true;

			Env env = new Env();
			env.player = activeChar;
			if (target instanceof L2Character) // TODO: object or char?
				env.target = (L2Character) target;

			//�������������
			if (!preCondition.test(env)) {
				if (activeChar instanceof L2SummonInstance) {
					((L2SummonInstance) activeChar).getOwner().sendPacket(
							new SystemMessage(
									SystemMessageId.PET_CANNOT_USE_ITEM));
					return false;
				}

				if (sendMessage) {
					String msg = preCondition.getMessage();
					int msgId = preCondition.getMessageId();
					if (msg != null) {
						activeChar.sendMessage(msg);
					} else if (msgId != 0) {
						SystemMessage sm = new SystemMessage(msgId);
						if (preCondition.isAddName())
							sm.addItemName(_itemId);
						activeChar.sendPacket(sm);
					}
				}
				
				return false;
			}
		}
		
		return true;
	}
	
	/**
	 * ��� ��Ʒ���������ַ�
	 * @return
	 */
	public String getAttributString()
	{
		if( _itemAttributeDes == null )
		{
			_itemAttributeDes = AttributeStringSplice.getInstance().getAttributeString( _attributs );
		}
		
		
		return _itemAttributeDes;
	}
	
	protected String _allItemAttributesDes; //
	
	/**
	 * �����Ʒģ������������ ���� ��Ʒ������
	 * 
	 * @return
	 */
	public String getAllAttributString()
	{
		if( _allItemAttributesDes == null )
		{
			_allItemAttributesDes = getName() + "<br/>";
//			_allItemAttributesDes += "���ۼ۸�:" + getSellPrice() + "����"+ "<br/>";
			
			StringBuilder sb = new StringBuilder();
			List<Condition> allCond = getAllCondions();
			
			if( AttributeStringSplice._allStringToString.get( getItemType().toString() ) != null )
			{
				sb.append("װ������:").append( AttributeStringSplice._allStringToString.get( getItemType().toString() ) ).append("<br/>");
			}
			
			for( Condition cond: allCond )
			{
				sb.append( cond.getCondtionDes() );
			}
			
			if( getBodyPart() != -1 )
			{
				sb.append("װ����λ:").append( AttributeStringSplice._allBodyPart.get( getBodyPart() ) ).append("<br/>");
			}
			
			if( getEnduranceup() != -1 )
				sb.append("�;ö�:").append( getEnduranceup()/100 ).append("/").append( getEnduranceup()/100 ).append("<br/>");
			
			_allItemAttributesDes += sb.toString();
			_allItemAttributesDes += getAttributString();
			_allItemAttributesDes += getItemDes();
		}

		return _allItemAttributesDes;
	}
		
	/**
	 * ��� ���ĵ�����
	 * @return
	 */
	public int getMaxStackNums()
	{
		return _stackmaxnums;
	}
	
	/**
	 *  ��� ����Ʒģ��� ���id
	 *  ���������Ʒʵ��id
	 * @return
	 */
	public int getItemCalId()
	{
		return getItemTypeId() + getItemType().ordinal();
	}
	
	/**
	 *  �����Ʒ����id
	 *  ÿ�����Ͷ��и�Ψһid
	 * @return
	 */
	public abstract int getItemTypeId();

	//��� ��Ʒ����ֵ ������
	
	/**
	 * ��� ָ�����Ե� ����ֵ
	 * imask : ָ���� ����ֵ ��ʾ
	 */
//	@SuppressWarnings("unchecked")
//	public ArrayList<Integer> getAttributeValue( int imask )
//	{
//		return (ArrayList<Integer>)_attributs.get( imask );
//	}
	
//	/** ��Ҫȥʵ�� ���!!!!!!!!
//	 * ��� ��Ʒ������ϵͳ �����Լӳ�ֵ
//	 * @return
//	 */
//	public ArrayList<Integer> getAssistAttributeValue()
//	{
//		return null;
//	}
	
	//end ��� ��Ʒ����ֵ

	/**
	 * Returns the name of the item
	 * 
	 * @return String
	 */
	@Override
	public String toString() {
		return _name;
	}
	
	public void OnlyFortest()
	{
		System.out.println( getAttributString() );
		System.out.println( _name );
		System.out.println( _stackmaxnums );
		System.out.println( _type );
		System.out.println( _type2 );
		System.out.println( _bodyPart );
	}
}
